package com.example.server.mapper;

import com.example.server.entity.Conversation;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ConversationMapper {

    //添加对话
    @Insert("INSERT INTO conversation (user_id,script_id) VALUES (#{user_id},#{script_id})")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    void insertConversation(Conversation conversation);

    //根据用户id查对应的对话，可能有多个
    @Select("SELECT * FROM conversation WHERE user_id = #{user_id}")
    List<Conversation> selectConversationsByUserId(@Param("user_id") Integer user_id);

    //根据对话id查相应的对话，方便载入
    @Select("SELECT * FROM conversation WHERE id = #{id}")
    Conversation selectConversationById(@Param("id") Integer id);

    // Delete conversation by ID
    @Delete("DELETE FROM conversation WHERE id = #{id}")
    void deleteConversationById(@Param("id") Integer id);

}
